package com.llmm.eduService.controller;

import com.llmm.bean.RestRet;
import com.llmm.eduService.entity.EduTeacher;
import com.llmm.eduService.service.EduTeacherService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("edu/teacher")
@Slf4j
public class EduTeacherController {

    @Autowired
    private EduTeacherService teacherService;

    //条件查询教师列表
    @GetMapping("queryTeachers")
    public RestRet<List<EduTeacher>> queryTeachersByParams(@RequestParam Map map){
        List<EduTeacher> eduTeachers = teacherService.queryTeachers(map);
        return new RestRet<>(eduTeachers,0,null);
    }

    //查询所有教师总数
    @GetMapping("getCount")
    public RestRet<Integer> getTeachersCount(@RequestParam Map map){
        Integer integer = teacherService.countTeachers(map);
        return new RestRet<>(integer,0,null);
    }

    //新增教师信息
    @PostMapping("saveTeacher")
    public RestRet<Integer> saveTeacher(@RequestBody EduTeacher teacher){
        Integer integer = teacherService.saveTeacher(teacher);
        return new RestRet<>(integer,0,null);
    }

    //修改教师信息
    @PutMapping("editTeacher")
    public RestRet<Integer> editTeacher(@RequestBody EduTeacher teacher){
        Integer integer = teacherService.updateTeacher(teacher);
        return new RestRet<>(integer,0,null);
    }

    //删除教师信息（前端传参，list<id>，可以进行批量删除）
    @PutMapping("delTeacher/{ids}")
    public RestRet<Integer> delTeacher(@PathVariable String ids){
        Integer count = teacherService.deleteById(ids);
        return new RestRet<>(count,0,null);
    }

    //查询单个教师信息
    @GetMapping("queryOne/{id}")
    public RestRet<EduTeacher> queryOne(@PathVariable String id){
        EduTeacher teacher = teacherService.queryTeacherById(id);
        return new RestRet<>(teacher,0,null);
    }


}
